//页面使用侧边栏 公用类（可设置用户名 角色，和所有菜单跳转链接）


$(function(){
	
	
	
	
	
	
	var username=localStorage.getItem("username");

	var config = apiManage.getMenuConfig();
	
	
	console.log("configs===="+JSON.stringify(config));

	//根据用户菜单权限设置菜单
	if(config!=null&&config.length>0){
		
		var readyHtml = "";
		for (var i =0;i<config.length;i++) {
//			var title = config[i].value;
			var title = config[i].key;

			var goParam = 1;
			var icon = "";
			
			if(title=='app:location:index'){//主动定位
				goParam=5;
				icon ="&#xe617;";
			}
			else if(title=='app:check:index'){//巡检管理
				goParam=3;
				icon ="&#xe685;";
			}
			else if(title=='app:resterminal:index'){//终端管理
				icon ="&#xe625;";
				goParam=1;
			}
			else if(title=='app:work:index'){//工单管理
				icon = "&#xe61f;";
				goParam=2;
			}
			else if(title=='app:alarm:index'){//告警展示
				icon ="&#xe604;";
				goParam=4;
			}
			else if(title=='app:gisterminal:index'){//GIS终端
				icon ="&#xe604;";
				goParam=6;
			}
			else if(title='app:operationanalysis:index'){//运营分析
				icon ="&#xe604;";
				goParam=7;
			}
			
			else{
				continue;

			}
			
			readyHtml+=
    	      "<li>"+
				"<a onclick='go("+goParam+");'>"+
				"<i class=\"iconfont\">"+icon+"</i>"+
				"<b>"+config[i].value+"</b>"+
				"</a>"+
				"</li>";
		}
		
		//console.log("html==="+readyHtml);
	}


	
	var html =" <header class=\"f_l maxbox menu_top\">"+
"        <h2>"+username+"</h2>"+
"        <b></b>"+
"      </header>"+
"      <menu class=\"f_l maxbox menu\" id=\"menu\">"+
"        <ul>"+readyHtml+

//"          <li>"+
//"            <a onclick='go(2);'>"+
//"              <i class=\"iconfont\" >&#xe61f;</i>"+
//"              <b>工单管理</b>"+
//"            </a>"+
//"          </li>"+
//"          <li>"+
//"            <a onclick='go(3);'>"+
//"              <i class=\"iconfont\">&#xe685;</i>"+
//"              <b>巡检管理</b>"+
//"            </a>"+
//"          </li>"+
//"          <li>"+
//"            <a onclick='go(4);'>"+
//"              <i class=\"iconfont\">&#xe604;</i>"+
//"              <b>告警展示</b>"+
//"            </a>"+
//"          </li>"+
//"          <li>"+
//"            <a onclick='go(1);'>"+
//"              <i class=\"iconfont\">&#xe625;</i>"+
//"              <b>终端管理</b>"+
//"            </a>"+
//"          </li>"+
//"          <li>"+
//"            <a  onclick='go(5);'>"+
//"              <i class=\"iconfont\">&#xe617;</i>"+
//"              <b>主动定位</b>"+
//"            </a>"+
//"          </li>"+
//"          <li>"+
//"            <a onclick='go(6);'>"+
//"              <i class=\"iconfont\">&#xe602;</i>"+
//"              <b>系统设置</b>"+
//"            </a>"+
//"          </li>"+

//"          <li>"+
//"            <a onclick='go(7);'>"+
//"              <i class=\"iconfont\">&#xe602;</i>"+
//"              <b>GIS终端</b>"+
//"            </a>"+
//"          </li>"+
"        </ul>"+
"      </menu>"+
" <footer class=\"f_l maxbox menu_foot\"><p>注销</p><a onclick='go(10);'><i class=\"iconfont\">&#xe618;</i></a></footer>";

	

	$(".sidenav").html(html);
	
	
	

});

function go(type){
	   		var timestamp=new Date().getTime();

			switch (type){
				case 1:
					hui.open("/modules/terminal/terminal.html?date="+timestamp, {}, true, {});
					break;
				case 2:
					hui.open("/modules/work/job_main.html?date="+timestamp, {}, true, {});
					break;
				case 3:
					hui.open("/modules/inspection/inspection.html?date="+timestamp, {}, true, {});
					break;
				case 4:
					hui.open("/modules/alerm/alarm_list.html?date="+timestamp, {}, true, {});
					break;
				case 5:
					hui.open("/modules/login/location.html?date="+timestamp, {}, true, {});
					break;
				case 6:
					hui.open("/modules/gisTerminal/gisTerminal_map.html?date="+timestamp, {}, true, {});

					break;
				case 7:
					hui.open("/modules/analysis/analysis_main.html?date="+timestamp);
					break;
	
				case 10:{
					var container = document.getElementById('wrapper');
					classie.remove( container, 'side_show' );

						
						if(localStorage.getItem("keep")=="true" ){
							localStorage.setItem("sec_pwd","");
							localStorage.setItem("userid","");
							localStorage.setItem("officeId","");
							localStorage.setItem("companyId","");
							localStorage.setItem("menuMap","");
							
							localStorage.setItem("worksArray","");
							localStorage.setItem("zdArray","");
							localStorage.setItem("xjArray","");

//								localStorage.setItem("username","");
//								localStorage.setItem("password","");
						}
						else{
						
//								localStorage.setItem("username","");
//								localStorage.setItem("password","");

								localStorage.setItem("sec_pwd","");
							localStorage.setItem("userid","");
							localStorage.setItem("officeId","");
							localStorage.setItem("companyId","");
							localStorage.setItem("menuMap","");
							
							localStorage.setItem("worksArray","");
							localStorage.setItem("zdArray","");
							localStorage.setItem("xjArray","");

//								localStorage.setItem("username","");
								localStorage.setItem("password","");

//							localStorage.clear();
						}

						console.log("localStorage--"+JSON.stringify(localStorage));
						hui.open("/login.html?date="+timestamp, {}, true, {});
					
					}
					break;
				default:
					break;
			}
			
		console.log(type);

	}
	
